package com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_adapter1;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.qingyiapp.R;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_lv;

import java.util.List;

public class adapter_address_lv extends BaseAdapter {

    List<JavaBean_lv.DataBean.ScenicsBeanX> scenics;
    Context context;

    public adapter_address_lv(List<JavaBean_lv.DataBean.ScenicsBeanX> scenics, Context context) {
        this.scenics = scenics;
        this.context = context;
    }

    @Override
    public int getCount() {
        return scenics.size();
    }

    @Override
    public Object getItem(int position) {
        return scenics.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        MyViewHolder myViewHolder = null;
        if(convertView==null){
            myViewHolder = new MyViewHolder();
            convertView = View.inflate(context, R.layout.address_rows,null);

            myViewHolder.recyclerView = convertView.findViewById(R.id.address_lv);
            myViewHolder.textView = convertView.findViewById(R.id.address_themes);

            convertView.setTag(myViewHolder);
        }else{
            myViewHolder = (MyViewHolder) convertView.getTag();
        }

        adapter_address_lv_rv adapter_address_lv_rv = new adapter_address_lv_rv(scenics.get(position).getScenics(),context);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);

        myViewHolder.recyclerView.setLayoutManager(linearLayoutManager);
        myViewHolder.recyclerView.setAdapter(adapter_address_lv_rv);

        myViewHolder.textView.setText(scenics.get(position).getTheme());

        return convertView;
    }

    class MyViewHolder{
        RecyclerView recyclerView;
        TextView textView;
    }

}
